package com.xxxy.dongyexuan.utils;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class TokenUtils {
    private static Set<String> tokens=new HashSet<>();
    private static String getToken(){
        Random random = new Random();//随机数类
        String str="";
        for(int i=0;i<20;i++){
            char ch = (char)(random.nextInt(26)+97);
            str+=ch;
        }
        str+=System.currentTimeMillis();
        return str;
    }
    public static String backToken(){
        String token = getToken();
        boolean iden=tokens.add(token);
        if(iden==true){
            return token;
        }else{
            return backToken();
        }
    }

    public static void main(String[] args) {
        String token=TokenUtils.backToken();
        System.out.println(token);
    }
}
